package tcp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/17 17:25
 * @description tcp服务端
 */
public class TcpServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(9999);
            Socket accept = serverSocket.accept();
            InputStream inputStream = accept.getInputStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] bytes = new byte[1024];
            int length;
            while ((length = inputStream.read()) != -1) {
                baos.write(bytes, 0, length);
            }
            System.out.println("baos = " + baos.toString());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
